<div id="app">
    <admin-page-header>
        <bi-button type="primary" @click="$go({action:'edit'})">添加页面</bi-button>
     </admin-page-header>
    <div class="container">
        <div class="row g-2">
            <div class="col-12">

                <bi-card title="搜索">
                    <div class="row g-2">
                        
                        <div class="col-12 col-sm-12 col-lg-12">
                            <bi-input v-model="search.keyword"  placeholder="" icon="fa fa-search" ></bi-input>
                        </div>
                    </div>
                </bi-card>
            </div>
            <div class="col-12">
                <bi-card title="页面列表">
                    <bi-table checkbox :data="list" :loading="loading" min-height="300">
                        <bi-table-column label="标题" name="title"></bi-table-column>
                        <bi-table-column label="模板" name="template"></bi-table-column>
                        <bi-table-column label="模型" name="model_title"></bi-table-column>
                        <bi-table-column label="管理" width="150"  v-slot="{row}">
                             <bi-button type="primary" @click="$go({action:'edit',gets:{id:row.page_id}})"  >编辑</bi-button>
                            <bi-button type="warning" @click="handleDel(row)" >删除</bi-button>
                        </bi-table-column>
                    </bi-table>
                    <template #footer>
                        <bi-pagination :page-size="20" v-model="page" :total="total" :count="count" ></bi-pagination>
                    </template>
                </bi-card>
            </div>
        </div>
    </div>
</div>

<script> 
import {debounce} from '@@/admin/assets/js/global.js';
let app = admin.createApp({
    data(){

        let search = {
            blockgroup_id:'',
            status:'',
            keyword:'',
        }

        search  = this.$assign(search,this.$status.get('search'));
        
        return {
            search,
            list:[],
            loading:false,
            page:this.$status.get('page')??1,
            total:0,
            count:0
        }
    },
    watch:{
        search:{
            handler:debounce(function(val){
                
                this.page = 1;
                this.refresh();
            },1000),
            deep:true
        },
        page(val){
            this.refresh();
        }        
    },
    methods:{
        handleDel(item){
            this.$confirm({text:'确定删除？',type:'warning'},()=>{
                this.$ajax({
                    url:this.$url({action:'del'}),
                    data:{
                        page_id:item.page_id
                    },
                    success:(res)=>{
                        this.refresh();
                        //this.$user.delLocalStorage('web-block-input');
                        this.$toast({text:'删除成功',type:'success'});
                    }
                })
            })
        },
        refresh(){
            this.$status.set('page',this.page);
            this.$status.set('search',this.search);
            
            this.$ajax({
                url:this.$url({action:'list'}),
                data:{
                    page:this.page,
                    ...this.search
                },
                success:(data)=>{
                    this.list = data.list;
                    this.total = data.total;
                    this.count = data.count;
                    this.loading = false;
                }
            })
        }
    },
    mounted(){
        this.refresh();
    }
}).mount('#app');
</script>